package com.macro.mall.mgb;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.Collections;

public class CodeGenerator {
    public static void main(String[] args) {
        String url = "jdbc:mysql://192.168.101.130:3306/mall?useSSL=false&serverTimezone=UTC";
        String username = "root";
        String password = "root";

        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("wangwang") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .dateType(DateType.ONLY_DATE) // 时间策略
                            .commentDate("yyyy-MM-dd") // 注释日期格式
                            .outputDir(System.getProperty("user.dir") + "/mall-mgb/src/main/java"); // 输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.macro.mall") // 父包名
                            .moduleName("mgb") // 模块名
                            .entity("model") // 实体类包名
                            .mapper("com/macro/mall/mgb/mapper") // mapper包名
                            .service("service") // service包名
                            .controller("controller") // controller包名
                            .pathInfo(Collections.singletonMap(OutputFile.xml,
                                    System.getProperty("user.dir") + "/mall-mgb/src/main/resources/mapper")); // xml路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(
                                    // 内容模块相关表
                                    "cms_help", "cms_help_category", "cms_member_report",
                                    "cms_prefrence_area", "cms_prefrence_area_product_relation",
                                    "cms_subject", "cms_subject_category", "cms_subject_comment",
                                    "cms_subject_product_relation", "cms_topic", "cms_topic_category",
                                    "cms_topic_comment",

                                    // 订单模块相关表
                                    "oms_cart_item", "oms_company_address", "oms_order",
                                    "oms_order_item", "oms_order_operate_history", "oms_order_return_apply",
                                    "oms_order_return_reason", "oms_order_setting",

                                    // 商品模块相关表
                                    "pms_album", "pms_album_pic", "pms_brand", "pms_comment",
                                    "pms_comment_replay", "pms_feight_template", "pms_member_price",
                                    "pms_product", "pms_product_attribute", "pms_product_attribute_category",
                                    "pms_product_category", "pms_product_attribute_value", "pms_product_category_attribute_relation",
                                    "pms_product_full_reduction", "pms_product_ladder", "pms_product_operate_log",
                                    "pms_sku_stock", "pms_product_vertify_record",

                                    //营销模块相关表
                                    "sms_coupon", "sms_coupon_history", "sms_coupon_product_category_relation",
                                    "sms_coupon_product_relation",
                                    "sms_flash_promotion",
                                    "sms_flash_promotion_log",
                                    "sms_flash_promotion_product_relation",
                                    "sms_flash_promotion_session",
                                    "sms_home_advertise",
                                    "sms_home_brand",
                                    "sms_home_new_product",
                                    "sms_home_recommend_product",
                                    "sms_home_recommend_subject",

                                    // 权限模块相关表
                                    "ums_admin", "ums_admin_login_log", "ums_admin_permission_relation",
                                    "ums_admin_role_relation", "ums_growth_change_history",
                                    "ums_integration_change_history", "ums_integration_consume_setting",
                                    "ums_member", "ums_member_level", "ums_member_login_log",
                                    "ums_member_receive_address", "ums_member_rule_setting",
                                    "ums_member_statistics_info", "ums_member_tag", "ums_member_task",
                                    "ums_menu", "ums_permission", "ums_resource", "ums_resource_category",
                                    "ums_role", "ums_role_menu_relation", "ums_role_permission_relation",
                                    "ums_role_resource_relation"
                            ) // 设置需要生成的表名
                            .addTablePrefix("cms_", "oms_", "pms_", "ums_") // 设置过滤表前缀
                            .entityBuilder()
                            .enableLombok() // 启用lombok
                            .idType(IdType.AUTO)// 强制使用AUTO策略
                            .enableTableFieldAnnotation() // 字段注解
                            .versionColumnName("version") // 乐观锁字段名
                            .logicDeleteColumnName("deleted") // 逻辑删除字段名
                            .formatFileName("%s") // 实体类文件名称格式
                            .controllerBuilder()
                            .enableRestStyle() // 开启RestController
                            .formatFileName("%sController") // controller文件名称格式
                            .serviceBuilder()
                            .formatServiceFileName("%sService") // service接口文件名称格式
                            .formatServiceImplFileName("%sServiceImpl") // service实现类文件名称格式
                            .mapperBuilder()
                            .formatMapperFileName("%sMapper") // mapper接口文件名称格式
                            .formatXmlFileName("%sMapper"); // xml文件名称格式
                })
                .templateEngine(new VelocityTemplateEngine()) // 使用Velocity引擎
                .execute();
    }
}